// 20090312
function Dialog(params) {
	this.childDialog;
	this.openFlag = false;
	this.isIe = (document.all) ? true : false;
	this.setSelectState = function(state) {
		var objl = document.getElementsByTagName('select');
		for (var i = 0; i < objl.length; i++) {
			objl[i].style.visibility = state;
		}
	};
	this.onClose = function() {
	};
	this.onOpen = function() {
	};
	this.showdiv = "rootDialog";
	this.title = "";
	this.url = "";
	if (this.isIe) {
		this.margin = 12;
	} else {
		this.margin = 12;
	}
	this.showdivWidth = 0;
	this.showdivHeight = 0;

	this.DivCss = "background:#ffffff;border:1px solid #A7C3C6;margin:0px auto;text-align:center;padding:0px;";

	this.titleDivCss = "text-align:center;margin:0px auto;padding:0px;";

	this.titleTableCss = "text-align:left;background:#EFF3F7;border:1px solid #ffffff;color:#000000;margin:0px auto;padding:0px; font-size:12px; line-height:20px;";

	this.titleTextCss = "text-align:left;margin:0px auto;";

	this.titleControlCss = "text-align:right;";

	this.ahrefcss = "text-decoration:none;text-align:right;";

	this.titleBottomDivCss = "margin:0px;border-bottom:1px solid #A7C3C6;line-height:1px;";
	
	this.contentDivCss = "background:#ffffff;overflow:auto;text-align:center;margin:0px auto;padding:0px;";

	this.showdivWidth = 0;
	this.showdivHeight = 0;
	if (params) {
		if (params.showdiv) {
			this.showdiv = params.showdiv;
		}
		if (params.onOpen) {
			this.onOpen = params.onOpen;
		}
		if (params.onClose) {
			this.onClose = params.onClose;
		}
		if (params.title) {
			this.title = params.title;
		}
		if (params.url) {
			this.url = params.url;
		}
		if (params.margin) {
			this.margin = params.margin * 2;
		}
		if (params.x) {
			this.showdivWidth = params.x;
		}
		if (params.y) {
			this.showdivHeight = params.y;
		}
	}
	this.closeWindow = function() {
		this.openFlag = false;
		if (this.back && this.back.parentNode) {
			this.back.parentNode.removeChild(this.back);
		}
		if (this.contentdiv && this.contentdiv.parentNode) {
			this.contentdiv.parentNode.removeChild(this.contentdiv);
		}
		if (this.o && this.o.parentNode) {
			this.o.parentNode.removeChild(this.o);
		}
		if (this.isIe && !rootDialog.openFlag) {
			this.setSelectState('');
		}
	};
}
// init one dialog
var rootDialog = new Dialog({
			showdiv : 'rootDialog'
		});
var tray = new Array();
function getXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e1) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
				}
			}
		}
	}
}

openDialog = function() {
	var obj;
	var paramsize = arguments.length;
	if (paramsize == 0) {
		obj = rootDialog;
	}
	if (paramsize >= 1) {
		if (c(arguments[0])) {
			obj = arguments[0];
		} else if (rootDialog) {
			obj = rootDialog;
		}
	}
	if (paramsize >= 2) {
		obj.url = arguments[1];
	}
	if (paramsize >= 3) {
		obj.onOpen = arguments[2];
	}
	if (paramsize >= 4&&arguments[3]) {
		obj.onClose = arguments[3];
	}
	obj.closeWindow();
	obj.openFlag = true;
	obj.back = document.body.appendChild(document.createElement("div"));
	obj.back.id = obj.showdiv + "_back";

	with (obj.back.style) {
		top = "0px";
		left = "0px";
		position = "absolute";
		background = "#E0E0E0";
		if (obj.isIe) {
			filter = "alpha(opacity=40)";
		} else {
			opacity = "0.40";
		}
		width = Math.min(parseInt(document.body.clientWidth),
				parseInt(document.body.scrollWidth))
				+ "px";
		height = Math.min(parseInt(document.body.clientHeight),
				parseInt(document.body.scrollHeight))
				+ "px";
	}

	obj.isdown = false;
	obj.divleft;
	obj.divtop;
	document.body.onmousemove = function(evt) {
		if (obj.isdown) {
			var events = evt;
			if (obj.isIe) {
				events = event;
			}
			obj.o.style.left = events.clientX - obj.divleft;
			obj.o.style.top = events.clientY - obj.divtop;
		}
	};

	obj.o = document.body.appendChild(document.createElement("div"));
	obj.o.id = obj.showdiv;
	obj.o.style.cssText = 'display:none;float:left;overflow:hidden;position:absolute;z-index:10;'
			+ obj.DivCss;
	obj.title_div = obj.o.appendChild(document.createElement("div"));
	obj.title_div.onmousedown = function(evt) {
		obj.isdown = true;
		var events = evt;
		if (obj.isIe) {
			events = event;
		}
		obj.divleft = events.clientX - parseInt(obj.o.style.left);
		obj.divtop = events.clientY - parseInt(obj.o.style.top);
	};
	
	obj.title_div.onmouseup = function(e) {
		obj.isdown = false;
	};
	obj.title_div.id = obj.showdiv + "_titlediv";
	
	obj.title_div.style.cssText = 'width:' + (obj.showdivWidth - 2)
				+ 'px;overflow:hidden;' + obj.titleDivCss;

	obj.title_table = obj.title_div
			.appendChild(document.createElement("table"));
	obj.titleline_table = obj.title_div.appendChild(document
			.createElement("div"));
	obj.titleline_table.style.cssText = "width:" + (obj.showdivWidth - 2)
			+ "px;" + obj.titleBottomDivCss;

	obj.titleline_table.cellSpacing = "0";
	obj.titleline_table.cellPadding = "0";
	

	obj.title_table.cellSpacing = "0";
	// obj.title_table.cellPadding = "0";
	obj.title_table.style.cssText = "width:" + (obj.showdivWidth - 2) + "px;"
			+ obj.titleTableCss;
	obj.title_table_thead = obj.title_table.appendChild(document
			.createElement("thead"));
	obj.title_table_tr = obj.title_table_thead.appendChild(document
			.createElement("tr"));

	obj.title_table_td1 = obj.title_table_tr.appendChild(document
			.createElement("td"));
	obj.title_table_td1.id = obj.showdiv + "_title";
	if (c(obj.title)) {
		obj.title_table_td1.innerHTML = "&nbsp;" + obj.title;
	}
	obj.title_table_td1.style.cssText = obj.titleTextCss;

	obj.title_table_td2 = obj.title_table_tr.appendChild(document
			.createElement("td"));
	obj.title_table_td2.style.cssText = obj.titleControlCss;
	obj.min_a = obj.title_table_td2.appendChild(document.createElement("a"));
	obj.min_a.href = "#";
	obj.min_a.style.cssText = obj.ahrefcss;

	obj.winState = 0;
	var padding = 0;
	if (obj.isIe) {
		padding = 2;
	}
	obj.min_a.onclick = function() {
		if (obj.winState != -1) {
			var bWidth = Math.ceil(parseInt(document.body.clientWidth) / 4);
			obj.o.style.left = "0px";
			if (tray.length > 3) {
				bWidth = Math.ceil(parseInt(document.body.clientWidth)
						/ (tray.length + 1));
			}
			for (var i = 0; i < tray.length; i++) {
				tray[i].o.style.width = (bWidth) + "px";
				tray[i].title_div.style.width = (bWidth) + "px";
				tray[i].title_table.style.width = (bWidth) + "px";
			}
			obj.o.style.left = tray.length * bWidth + "px";
			tray.push(obj);
			var bHeight = parseInt(obj.title_div.clientHeight);
			if (!obj.isIe) {
				obj.o.style.top = (parseInt(document.body.clientHeight)
						- bHeight - 2)
						+ "px";
			} else {
				obj.o.style.top = (parseInt(document.body.clientHeight) - bHeight)
						+ "px";
			}
			obj.back.style.display = "none";

			obj.o.style.height = bHeight + "px";
			obj.o.style.width = bWidth + "px";
			obj.title_div.style.width = (bWidth) + "px";
			obj.title_table.style.width = (bWidth) + "px";
			obj.winState = -1;
		}
	};
	obj.min_a.innerHTML = "&nbsp;_&nbsp;";

	obj.max_a = obj.title_table_td2.appendChild(document.createElement("a"));
	obj.max_a.href = "#";
	obj.max_a.style.cssText = obj.ahrefcss;
	obj.max_a.onclick = function() {
		var flag = false;
		var bWidth = Math.ceil(parseInt(document.body.clientWidth) / 4);
		if (tray.length > 4) {
			bWidth = Math.ceil(parseInt(document.body.clientWidth)
					/ (tray.length - 1));
		}
		for (var i = 0; i < tray.length; i++) {
			tray[i].o.style.width = (bWidth) + "px";
			tray[i].title_div.style.width = (bWidth) + "px";
			tray[i].title_table.style.width = (bWidth) + "px";
		}
		for (var i = 0; i < tray.length; i++) {
			if (flag) {
				tray[i].o.style.left = i * bWidth + "px";
			}
			if (tray[i] == obj) {
				var temp1 = tray.splice(i, 1);
				flag = true;
				i--;
			}
		}
		obj.back.style.display = "";
		if (obj.winState != 0) {
			computeDialogSize(obj);
			obj.winState = 0;
		} else {
			var bWidth = Math.min(parseInt(document.body.clientWidth),
					parseInt(document.body.clientWidth));
			var bHeight = Math.min(parseInt(document.body.clientHeight),
					parseInt(document.body.scrollHeight));
			if (!obj.isIe) {
				bWidth -= 4;
				bHeight -= 4;
			} else {
				bWidth -= 4;
				bHeight -= 4;
			}
			obj.o.style.top = "1px";
			obj.o.style.left = "1px";
			obj.o.style.height = bHeight + "px";
			obj.o.style.width = bWidth + "px";
			obj.title_div.style.width = (bWidth - padding) + "px";
			obj.title_table.style.width = (bWidth - padding) + "px";
			obj.contentdiv.style.width = (bWidth - padding) + "px";
			obj.contentdiv.style.height = (bWidth - padding) + "px";
			obj.contentDivCss = "background:#ffffff;overflow:yes;text-align:center;margin:0px auto;padding:0px;";
			// dialogResize(obj);
			obj.winState = 1;
		}
	};
	obj.max_a.innerHTML = "&nbsp;\u53e3&nbsp;";

	obj.close_a = obj.title_table_td2.appendChild(document.createElement("a"));
	obj.close_a.href = "#";
	obj.close_a.style.cssText = obj.ahrefcss;
	obj.close_a.onclick = function() {
		closeDialog(obj);
	};
	obj.close_a.innerHTML = "&nbsp;\uff38&nbsp;";

	obj.contentdiv = obj.o.appendChild(document.createElement("div"));
	obj.contentdiv.id = obj.showdiv + '_content';
	obj.contentdiv.style.cssText = obj.contentDivCss;

	if (obj.isIe) {
		obj.setSelectState('hidden');
	}
	window.onresize = function() {
		dialogResize(obj);
	};

	var bWidth = parseInt(document.body.clientWidth);
	var bHeight = parseInt(document.body.clientHeight);
	with (obj.o.style) {
		display = "block";
		width = obj.showdivWidth + "px";
		height = obj.showdivHeight + "px";
		top = (Math.ceil((bHeight - obj.showdivHeight) / 2) < 0 ? 0 : Math
				.ceil((bHeight - obj.showdivHeight) / 2))
				+ "px";
		left = (Math.ceil((bWidth - obj.showdivWidth) / 2) < 0 ? 0 : Math
				.ceil((bWidth - obj.showdivWidth) / 2))
				+ "px";
	}
	var w = 0;
	var h = 0;
	var x;
	if (c(obj.url)) {
		// dialog/selcolor.htm?action=bgcolor
		var paramindex = obj.url.indexOf('?');
		if (paramindex != -1) {
			var params = obj.url.substring(paramindex + 1).split('&');;
			for (var i = 0; i < params.length; i++) {
				var param = params[i].split('=');
				URLParams[param[0]] = encodeURIComponent(param[1]);
			}
			obj.url = obj.url + "&sorc=" + ((new Date()).getTime());
		} else {
			obj.url = obj.url + "?sorc=" + ((new Date()).getTime());
		}
		x = getXMLHttpRequest();

		x.onreadystatechange = function() {
			if (x.readyState == 4) {
				if (x.status == 200) {
					var text = x.responseText;
					var scripttext = '';
					var scripttag = getNode(text, 'script');
					while (scripttag.beginI >= 0) {
						scripttext += scripttag.innerText;
						text = text.substring(0, scripttag.beginI)
								+ text.substring(scripttag.endI_end);
						scripttag = getNode(text, 'script');
					}
					scripttext += getNodeAttribName(text, 'body', 'onload');
					obj.contentdiv.innerHTML = text;
					if (obj.title) {
						obj.title_table_td1.innerHTML = "&nbsp;" + obj.title;
					} else {
						obj.title_table_td1.innerHTML = "&nbsp;"
								+ getNode(text, 'title').innerText;
					}
					computeDialogSize(obj);
					if (c(scripttext)) {
						loadJS("temp", scripttext);
					}

					if (c(obj.onOpen)) {
						setTimeout(obj.onOpen, 500);
					}

				}
			}
		};
		x.open('get', obj.url, true);
		x.send(null);
	} else {
		if (obj.showdivWidth >= bWidth) {
			obj.showdivWidth = bWidth;
			obj.o.style.left = 0 + "px";
		} else {
			obj.o.style.left = (Math.ceil((bWidth - obj.showdivWidth) / 2) < 0
					? 0
					: Math.ceil((bWidth - obj.showdivWidth) / 2))
					+ "px";
		}
		obj.title_div.style.width = (obj.showdivWidth) + "px";;
		obj.title_table.style.width = (obj.showdivWidth) + "px";
		obj.o.style.width = (obj.showdivWidth + 2) + "px";
		obj.contentdiv.style.width = (obj.showdivWidth + 6) + "px";
		if (obj.showdivHeight > bHeight) {
			obj.showdivHeight = bHeight;
			obj.o.style.top = 0 + "px";
		} else {
			obj.o.style.top = (Math.ceil((bHeight - obj.showdivHeight) / 2) < 0
					? 0
					: Math.ceil((bHeight - obj.showdivHeight) / 2))
					+ "px";

		}
		obj.o.style.height = (obj.showdivHeight + 31) + "px";
		obj.contentdiv.style.height = (obj.showdivHeight) + "px";
		if (c(obj.onOpen)) {
			setTimeout(obj.onOpen, 100);
		}
	}
};
function dialogClose(dialog) {
	var dialogTemp = rootDialog;
	if (dialog) {
		dialogTemp = dialog;
	}
	if (dialogTemp.childDialog && dialogTemp.childDialog.openFlag) {
		dialogClose(dialogTemp.childDialog);
	} else {
		document.body.onmousemove = function(evt) {
			var events = evt;
			if (dialogTemp.isIe) {
				events = event;
			}
			if (dialogTemp) {
				if (dialogTemp.openFlag) {
					if (dialogTemp.isdown) {
						dialogTemp.o.style.left = events.clientX
								- dialogTemp.divleft;
						dialogTemp.o.style.top = events.clientY
								- dialogTemp.divtop;
					}
				}
			}
		};
		if (dialogTemp) {
			if (dialogTemp.openFlag) {
				dialogTemp.title_div.onmousedown = function(evt) {
					dialogTemp.isdown = true;
					var events = evt;
					if (dialogTemp.isIe) {
						events = event;
					}
					dialogTemp.divleft = events.clientX
							- parseInt(dialogTemp.o.style.left);
					dialogTemp.divtop = events.clientY
							- parseInt(dialogTemp.o.style.top);
				};
				dialogTemp.title_div.onmouseup = function(e) {
					dialogTemp.isdown = false;
				};
			}
		}
	}
}

function dialogResize(dialog) {
	var dialogTemp = rootDialog;
	if (dialog) {
		dialogTemp = dialog;
	}
	if (dialogTemp.openFlag) {
		computeDialogSize(dialogTemp);
	}
	if (dialogTemp.back) {
		var bWidth = Math.min(parseInt(document.body.clientWidth),
				parseInt(document.body.scrollWidth));
		var bHeight = Math.min(parseInt(document.body.clientHeight),
				parseInt(document.body.scrollHeight));
		dialogTemp.back.style.width = bWidth + "px";
		dialogTemp.back.style.height = bHeight + "px";
	}
	if (dialogTemp.childDialog && dialogTemp.childDialog.openFlag) {
		dialogResize(dialogTemp.childDialog);
	}
}
// close dialog window
closeDialog = function(obj) {
	obj.onClose();
	// if exist child
	if (obj.childDialog) {
		// if child is Array
		if (obj.childDialog.length) {
			for (var i = 0; i < childDialog.length; i++) {
				// if child is open
				if (obj.childDialog[i].openFlag) {
					// close child
					closeDialog(obj.childDialog[i]);
				}
			}
		} else {
			if (obj.childDialog.openFlag) {
				closeDialog(obj.childDialog);
			}
		}
	}
	obj.o.style.display = "none";
	obj.closeWindow();
	obj.openFlag = false;
	dialogClose();
};
// adjust dialog window size
function computeDialogSize(win) {
	var w = win.margin;
	var h = win.margin;
	var padding = 2;
	if (!document.all) {
		padding = 0;
	}
	var childobj = win.contentdiv.childNodes;
	for (var i = 0; i < childobj.length; i++) {
		if (childobj[i]) {
			if (childobj[i].clientWidth)
				w += childobj[i].clientWidth;
			// var childobjchild = childobj[i].childNodes;
			// var tw=0;
			// for (var j = 0; j < childobjchild.length; j++) {
			// if(childobjchild[j]){
			// tw += childobjchild[i].clientWidth;
			// }
			// }
			// alert(w+":"+tw)
			// w=Math.max(w,tw);
			if (childobj[i].clientHeight)
				h += childobj[i].clientHeight;
		}
	}
	if (win.showdivWidth > 0) {
		w = win.showdivWidth;
	}
	if (win.showdivHeight > 0) {
		h = win.showdivHeight;
	}
	var bWidth = parseInt(document.body.clientWidth);
	if (w > bWidth) {
		w = bWidth;
		win.o.style.left = "0px";
	} else {
		win.o.style.left = (Math.ceil((bWidth - w) / 2) < 0 ? 0 : Math
				.ceil((bWidth - w) / 2))
				+ "px";
	}
	win.title_div.style.width = w - padding + "px";
	win.title_table.style.width = w - padding + "px";
	win.o.style.width = (w) + "px";
	win.contentdiv.style.width = w - padding + "px";

	var bHeight = parseInt(document.body.clientHeight);
	h += win.title_div.clientHeight;
	if (h > bHeight) {
		h = bHeight;
		win.o.style.top = "0px";
	} else {
		win.o.style.top = (Math.ceil((bHeight - h) / 2) < 0 ? 0 : Math
				.ceil((bHeight - h) / 2))
				+ "px";
	}
	win.o.style.height = h + "px";
	win.contentdiv.style.height = (h - win.title_div.clientHeight - padding)
			+ "px";
}
function $nav(o) {
	var obj = $no(o);
	var value = new Array();
	if (obj) {
		if (c(obj.length)) {
			for (var i = 0; i < obj.length; i++) {
				value[i] = obj[i].value;
			}
		} else {
			value[0] = obj.value;
		}
	}
	return value;
}
function $av(o) {
	var obj = $o(o);
	var value = new Array();
	if (obj) {
		if (c(obj.length)) {
			value = new Array();
			for (var i = 0; i < obj.length; i++) {
				value[i] = obj[i].value;
			}
		} else {
			value[0] = obj.value;
		}
	}
	return value;
}
function $v(o) {
	var obj = $o(o);
	var value = new Array();
	if (obj) {
		if (c(obj.length)) {
			for (var i = 0; i < obj.length; i++) {
				value[i] = obj[i].value;
			}
		} else {
			value[0] = obj.value;
		}
	}
	return value;
}

function c(o) {
	if (o == null) {
		return false;
	} else if (!o) {
		return false;
	} else {
		if (o.toString().length == 0) {
			return false;
		}
	}
	return true;
}

function $o(o) {
	var obj = $Q(o);
	var objs = null;
	if (obj) {
		if (obj.length) {
			objs = new Array();
			if (obj.options) {
				if (obj.multiple) {
					for (var i = 0; i < obj.options.length; i++) {
						if (obj.options[i].selected) {
							objs.push(obj[i]);
						}
					}
					return objs;
				} else {
					return (obj.options[obj.selectedIndex]);
				}
			} else {
				for (var i = 0; i < obj.length; i++) {
					if (obj[i].checked == true) {
						objs.push(obj[i]);
					}
				}
				return objs;
			}
		} else {
			if (obj.checked && obj.checked == true) {
				objs = obj;
			} else {
				objs = obj;
			}
		}
	}
	return objs;
}
function $no(o) {
	var obj = $Q(o);
	var objs = null;
	if (c(obj)) {
		if (c(obj.length)) {
			objs = new Array();
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].checked == false) {
					objs.push(obj[i]);
				}
			}
		} else {
			if (obj.checked == false) {
				objs = obj;
			}
		}
	}
	return objs;
}
function $Q(o) {
	var obj;
	try {
		if (document.all) {
			obj = eval("document.all." + o);
		} else {
			obj = document.getElementsByName(o);
		}
		if (!obj || !obj.length || (obj.length && obj.length == 1)) {
			return document.getElementById(o);
		}
	} catch (e) {
		return document.getElementById(o);
	}
	return obj;
}
function initRadio(n, v) {
	var obj = $Q(n);
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].value.Trim() == v.toString().Trim()) {
			obj[i].checked = true;
		} else {
			obj[i].checked = false;
		}
	}
}
function initCheckbox(n, v) {
	var obj = $Q(n);
	for (var i = 0; i < obj.length; i++) {
		if (v.indexOf(obj[i].value + ";") != -1) {
			obj[i].checked = true;
		} else {
			obj[i].checked = false;
		}
	}
}
function initCheckboxs(n, v) {
	var obj = $Q(n);
	if (!obj.length) {
		if (v == obj.value) {
			obj.checked = true;
		}
	} else {
		for (var i = 0; i < obj.length; i++) {
			if (v == obj[i].value) {
				obj[i].checked = true;
			}
		}
	}
}
function ioCheckbox(n) {
	var obj = $Q(n);
	if (obj) {
		if (obj.length) {
			for (var i = 0; i < obj.length; i++) {
				obj[i].checked = !obj[i].checked;
			}
		} else {
			obj.checked = !obj.checked;
		}
	}
}
function allCheckbox(n, thisobj) {
	var obj = $Q(n);
	if (obj) {
		if (obj.length) {
			for (var i = 0; i < obj.length; i++) {
				obj[i].checked = thisobj.checked;
			}
		} else {
			obj.checked = thisobj.checked;
		}
	}

}
function initSelect(n, v) {
	var obj = $Q(n);
	if (obj.length) {
		for (var i = 0; i < obj.length; i++) {
			if (obj[i].value == v.Trim()) {
				obj[i].selected = true;
			} else {
				obj[i].selected = false;
			}
		}
	}
}
// get node by tagNodeName from text
function getNode(text, tagNodeName) {
	var tagNode = new Object();
	tagNode.beginI = text.toLowerCase().indexOf('<' + tagNodeName);
	tagNode.beginI_end = tagNode.beginI
			+ (text.substring(tagNode.beginI)).indexOf('>') + 1;
	tagNode.beginText = text.substring(tagNode.beginI, tagNode.beginI_end);
	tagNode.endI = text.toLowerCase().indexOf('</' + tagNodeName);
	tagNode.endI_end = tagNode.endI
			+ (text.substring(tagNode.endI)).indexOf('>') + 1;
	tagNode.endText = text.substring(tagNode.endI, tagNode.endI_end);
	tagNode.innerText = text.substring(tagNode.beginI_end, tagNode.endI);
	return tagNode;
}
// get node by tagNodeName attributeName from text
function getNodeAttribName(text, tagNodeName, attributeName) {
	var node = getNode(text, tagNodeName).beginText;

	var attName_i = node.toLowerCase().indexOf(attributeName.toLowerCase());
	if (attName_i == -1) {
		return '';
	}
	var attValue_i = attName_i + node.substring(attName_i).indexOf('=') + 1;
	var attValue = trim(node.substring(attValue_i));
	var maxlength = attValue.length;
	var flag1_i = attValue.indexOf("' ") == -1 ? maxlength : attValue
			.indexOf("' ");
	var flag2_i = attValue.indexOf('" ') == -1 ? maxlength : attValue
			.indexOf('" ');
	var flag3_i = attValue.indexOf(' ') == -1 ? maxlength : attValue
			.indexOf(' ');
	var flag4_i = attValue.indexOf("'>") == -1 ? maxlength : attValue
			.indexOf("'>");
	var flag5_i = attValue.indexOf('">') == -1 ? maxlength : attValue
			.indexOf('">');
	var flag6_i = attValue.indexOf('>') == -1 ? maxlength : attValue
			.indexOf('>');
	var flag_i = Math.min(flag1_i, flag2_i, flag3_i, flag4_i, flag5_i, flag6_i);
	var temp = attValue.substring(0, flag_i).replace('"', '').replace("'", "");
	if (temp.indexOf(';') != temp.length) {
		temp += ";";
	}
	return temp;
}
// add event
function addEvent(eventName, name, scripttext) {
	var eventNames = ['', ''];
	switch (eventName) {
		case 'onclick' :
			eventNames[0] = 'onclick';
			eventNames[1] = 'click';
			break;
		case 'onmouseout' :
			eventNames[0] = 'onmouseout';
			eventNames[1] = 'mouseout';
			break;
		case 'onmouseover' :
			eventNames[0] = 'onmouseover';
			eventNames[1] = 'mouseover';
			break;
		case 'onclick' :
			eventNames[0] = 'onclick';
			eventNames[1] = 'click';
			break;
		case 'onclick' :
			eventNames[0] = 'onclick';
			eventNames[1] = 'click';
			break;
	}
	if (window.addEventListener) { // Mozilla, Netscape, Firefox
		$Q(name).addEventListener(eventNames[1], eval(scripttext), false);
	} else { // IE
		$Q(name).attachEvent(eventNames[0], function() {
					eval(scripttext);
				});
	}
}

RegExp.prototype.match = RegExp.prototype.test;

RegExp.escape = function(str) {
	return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
};

ScriptFragment = '<script[^>]*>([\\S\\s]*?)<\/script>';

stripTags = function() {
	return this.replace(/<\/?[^>]+>/gi, '');
};

stripScripts = function() {
	return this.replace(new RegExp(ScriptFragment, 'img'), '');
};

extractScripts = function() {
	var matchAll = new RegExp(ScriptFragment, 'img');
	var matchOne = new RegExp(ScriptFragment, 'im');
	return (this.match(matchAll) || []).map(function(scriptTag) {
				return (scriptTag.match(matchOne) || ['', ''])[1];
			});
};
function trim(str) {
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function s2u(s) {
	return encodeURIComponent(s);
}
// dynamic load javascript or js file
function loadJS(jsId, jstext) {
	if (c(jstext)) {
		var oHead = document.getElementsByTagName('HEAD').item(0);
		var oScript = document.createElement("script");
		oScript.language = "javascript";
		oScript.type = "text/javascript";
		oScript.id = jsId;
		if (jstext.indexOf('.js') == jstext.length - 3) {
			oScript.src = jstext;
		} else {
			oScript.defer = true;
			oScript.text = jstext;
		}
		oHead.appendChild(oScript);
	}
}

function formatSelectCss(obj) {
	removeformatSelectCss();
	var selectobjs = obj.o.getElementsByTagName('select');
	var padding = (document.all) ? 2 : 0;
	for (var i = 0; i < selectobjs.length; i++) {
		var temp = selectobjs[i];
		var rect = temp.getBoundingClientRect();
		temp.style.position = "absolute";
		temp.style.clip = "rect(2px," + (rect.right - rect.left - 2) + "px,"
				+ (rect.bottom - rect.top - 2) + "px,2px)";
		var tdiv = obj.o.appendChild(document.createElement("div"));
		tdiv.id = "selectdiv" + i;
		tdiv.style.cssText = "position:absolute;border:1px solid #000000;";
		tdiv.style.top = (temp.style.top - padding);
		tdiv.style.left = (temp.style.left - padding);
		tdiv.style.height = (temp.clientHeight + padding - 2);
		tdiv.style.width = (temp.clientWidth - 2 + padding);
	}
}
function removeformatSelectCss() {
	var tempi = 0;
	while ($Q("selectdiv" + i)) {
		$Q("selectdiv" + i).parentNode.removeChild($Q("selectdiv" + i));
		i++;
	}
}
function openDefaultPage(left, mainFrame) {
	if (left != "#")
		window.parent.frames['left'].location = left;
	if (mainFrame != "#")
		window.parent.frames['mainFrame'].location = mainFrame;
}
function $get(name) {
	var all = document.getElementsByTagName("input");
	var returnobj = new Array();
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			returnobj[returnobj.length] = obj;
		}
	}
	all = document.getElementsByTagName("textarea");
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			returnobj[returnobj.length] = obj;
		}
	}
	all = document.getElementsByTagName("select");
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			var tempobj = obj.options;
			for (var j = 0; j < tempobj.length; j++) {
				if (tempobj[j].selected) {
					returnobj[returnobj.length] = tempobj[j];
				}

			}
		}
	}
	if (returnobj && returnobj.length && returnobj.length == 1) {
		return returnobj[0];
	}
	return returnobj;
}
function $getV(name, sign) {
	var all = document.getElementsByTagName("input");
	var value = "";
	sign = sign ? sign : ';';
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			if (obj.type == "text" || obj.type == "hidden" || obj.checked) {
				value += sign + obj.value;
			}
		}
	}
	all = document.getElementsByTagName("textarea");
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			value += sign + obj.value;
		}
	}
	all = document.getElementsByTagName("select");
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			var tempobj = obj.options;
			for (var j = 0; j < tempobj.length; j++) {
				if (tempobj[j].selected) {
					value += sign + tempobj[j].value;
				}

			}
		}
	}
	if(value){
		value=value.substring(sign.length, value.length);
	}
	return value;
}
function $ngetV(name, sign) {
	var all = document.getElementsByTagName("input");
	var value = "";
	sign = sign ? sign : ';';
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			if ((obj.type == "checkbox" || obj.type == "radio") && !obj.checked) {
				value += sign + obj.value;
			}
		}
	}
	if(value){
		value=value.substring(sign.length, value.length);
	}
	return value;
}
function $setV(name, value, sign) {
	var all = document.getElementsByTagName("input");
	sign = sign ? sign : ';';
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			if (obj.type == "text" || obj.type == "hidden") {
				obj.value = value;
			} else if (obj.type == "radio" && obj.value == value) {
				obj.checked = true;
				break;
			} else if (obj.type == "checkbox") {
				var tempvalue = value.split(sign);
				for (var j = 0; j < tempvalue.length; j++) {
					if (tempvalue[j] == obj.value) {
						obj.checked = true;
						break;
					}
				}
			}
		}

	}
	all = document.getElementsByTagName("textarea");
	for (var i = 0; i < all.length; i++) {
		var obj = all[i];
		if (obj.id == name || obj.name == name) {
			obj.value = value;
		}
	}
	all = document.getElementsByTagName("select");
	for (var i = 0; i < all.length; i++) {
        var obj = all[i];
        if (obj.id == name || obj.name == name) {
            var options = obj.options;
            for(var j=0;j<options.length;j++){
                if (options[j].value==value) {
                    options[j].selected = true;
                }
            }
        }
    }
	return value.substring(sign.length, value.length);
}
function trim_value(inputString) {
	if (typeof inputString != "string") {
		return inputString;
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length - 1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}
	while (retValue.indexOf(';') > -1) {
		retValue = retValue.replace(';', '\uff1b');
	}
	while (retValue.indexOf('<') > -1) {
		retValue = retValue.replace('<', '&lt;');
	}
	while (retValue.indexOf('>') > -1) {
		retValue = retValue.replace('>', '&gt;');
	}
	while (retValue.indexOf('--') > -1) {
		retValue = retValue.replace('--', '\u2014\u2014');
	}
	while (retValue.indexOf(",") > -1) {
		retValue = retValue.replace(",", "\uff0c");
	}
	while (retValue.indexOf("'") > -1) {
		retValue = retValue.replace("'", "\u2019");
	}
	while (retValue.indexOf("?") > -1) {
		retValue = retValue.replace("?", "\uff1f");
	}
	while (retValue.indexOf("(|)") > -1) {
		retValue = retValue.replace("(|)", "\uff08|\uff09");
	}
	while (retValue.indexOf("exec") > -1) {
		retValue = retValue.replace("exec ", "\uff45\uff58\uff45\uff43 ");
	}
	while (retValue.indexOf("insert") > -1) {
		retValue = retValue.replace("insert ", "\uff49\uff4e\uff53\uff45\uff52\uff54 ");
	}
	while (retValue.indexOf("select") > -1) {
		retValue = retValue.replace("select ", "\uff53\uff45\uff4c\uff45\uff43\uff54 ");
	}
	while (retValue.indexOf("delete") > -1) {
		retValue = retValue.replace("delete ", "\uff44\uff45\uff4c\uff45\uff54\uff45 ");
	}
	while (retValue.indexOf("update") > -1) {
		retValue = retValue.replace("update ", "\uff55\uff50\uff44\uff41\uff54\uff45 ");
	}
	while (retValue.indexOf("count") > -1) {
		retValue = retValue.replace("count", "\uff43\uff4f\uff55\uff4e\uff54");
	}
	while (retValue.indexOf("*") > -1) {
		retValue = retValue.replace(" * ", " \uff0a ");
	}
	while (retValue.indexOf("%") > -1) {
		retValue = retValue.replace("%", "\uff05");
	}
	while (retValue.indexOf("chr") > -1) {
		retValue = retValue.replace("chr", "\uff43\uff48\uff52");
	}
	while (retValue.indexOf("mid") > -1) {
		retValue = retValue.replace("mid", "\uff4d\uff49\uff44");
	}
	while (retValue.indexOf("master") > -1) {
		retValue = retValue.replace("master", "\uff4d\uff41\uff53\uff54\uff45\uff52");
	}
	while (retValue.indexOf("truncate") > -1) {
		retValue = retValue.replace("truncate", "\uff54\uff52\uff55\uff4e\uff43\uff41\uff54\uff45");
	}
	while (retValue.indexOf("char") > -1) {
		retValue = retValue.replace("char", "\uff43\uff48\uff41\uff52");
	}
	while (retValue.indexOf("declare") > -1) {
		retValue = retValue.replace("declare", "\uff44\uff45\uff43\uff4c\uff41\uff52\uff45");
	}
	return retValue;
}